using System.IO;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System;
namespace mock_ehr_lib.Model
{
    public class ContinuityOfCareDocumentSerializer
    {
        private const string DeserializerExceptionMessage = "Error deserializing continuity of care document: {0}";

        public POCD_MT000040ClinicalDocument Deserialize(string filename)
        {
            POCD_MT000040ClinicalDocument ccd = null;
            try
            {
                using (TextReader reader = new StreamReader(filename))
                {
                    var serializer = new XmlSerializer(typeof(POCD_MT000040ClinicalDocument));
                    ccd = serializer.Deserialize(reader) as POCD_MT000040ClinicalDocument;
                }
            }
            catch (Exception exception)
            {
                throw new SerializationException(string.Format(DeserializerExceptionMessage, filename), exception);
            }
            return ccd;
        }
    }
}